package org.raymond.iworks.study.basic.designpattern.prototype.deepclone;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
public class Client {
    public static void main(String[] args) {
        DeepProtoType p = new DeepProtoType();
        p.setName("宋江");
        p.setTarget(new DeepCloneableTarget("大牛", "小妞"));

        // 浅拷贝
        DeepProtoType p0 = (DeepProtoType)p.clone();
        // 深拷贝-方式1
        DeepProtoType p1 = (DeepProtoType)p.deepClone1();
        // 深拷贝-方式2
        DeepProtoType p2 = (DeepProtoType)p.deepClone2();

        System.out.printf("p name:%s, target:%s, hashcode:%d\n", p.getName(), p.getTarget(), p.getTarget().hashCode());
        System.out.printf("p0 name:%s, target:%s, hashcode:%d\n", p0.getName(), p0.getTarget(), p.getTarget().hashCode());
        System.out.printf("p1 name:%s, target:%s, hashcode:%d\n", p1.getName(), p1.getTarget(), p.getTarget().hashCode());
        System.out.printf("p2 name:%s, target:%s, hashcode:%d\n", p2.getName(), p2.getTarget(), p.getTarget().hashCode());

        p0.getTarget().setCloneName("大牛0");
        p1.getTarget().setCloneClass("小牛1");
        p2.getTarget().setCloneName("大牛2");
        System.out.println("修改数据后");
        System.out.printf("p name:%s, target:%s, hashcode:%d\n", p.getName(), p.getTarget(), p.getTarget().hashCode());
        System.out.printf("p0 name:%s, target:%s, hashcode:%d\n", p0.getName(), p0.getTarget(), p.getTarget().hashCode());
        System.out.printf("p1 name:%s, target:%s, hashcode:%d\n", p1.getName(), p1.getTarget(), p.getTarget().hashCode());
        System.out.printf("p2 name:%s, target:%s, hashcode:%d\n", p2.getName(), p2.getTarget(), p.getTarget().hashCode());
    }
}
